//
// Created by jsjxsy on 2022/8/18.
// ++ 可以作为成员函数或者非成员函数(友元函数)
//
#include <iostream>
using namespace std;
class Point {
 public:
  Point(int x = 0, int y = 0) : x(x), y(y) {
    cout << "construct Point(x=" << x << ",y=" << y << ")" << endl;
  }

  Point operator+(const Point &other) const {
    return Point(x + other.x, y + other.y);
  };
  //Point operator++();//前置++
  Point &operator++();//前置++
  Point operator++(int);//后置++
  Point &operator--();//前置--
  Point operator--(int);//后置--
  int getX();
  int getY();
 private:
  int x;
  int y;
};

//Point Point::operator++() {
//  x++;
//  y++;
//  return Point(x, y);
//}
int Point::getX() {
  return x;
}
int Point::getY() {
  return y;
}
Point &Point::operator++() {
  x++;
  y++;
  return *this;
}
Point Point::operator++(int) {
  return Point(x++, y++);
}
Point &Point::operator--() {
  x--;
  y--;
  return *this;
}
Point Point::operator--(int) {
  return Point(x--, y--);
}

int main() {
  Point p1(1, 1);
  Point p2(3, 5);
  Point p3;
  p3 = p1 + p2;//4,6
  cout << "p3(x=" << p3.getX() << ",y=" << p3.getY() << ")" << endl;
  ++p3;//5,7
  cout << "p3(x=" << p3.getX() << ",y=" << p3.getY() << ")" << endl;
  p3++;
  //(6,8)
  cout << "p3(x=" << p3.getX() << ",y=" << p3.getY() << ")" << endl;
  --p3;
  cout << "p3(x=" << p3.getX() << ",y=" << p3.getY() << ")" << endl;
  p3--;
  cout << "p3(x=" << p3.getX() << ",y=" << p3.getY() << ")" << endl;
  return 0;
}
